#!/usr/local/bin/python

# __    _____ _____ _____    ___     ___ 
#|  |  |  _  |     |   __|  |_  |   |   |
#|  |__|     | | | |__   |   _| |_ _| | |
#|_____|__|__|_|_|_|_____|  |_____|_|___|

# Script to return average call duration
# Author: Carl Javier 4088697
# Date: 21 September 2008

#used to see if any locals calls were made
# from call records

import sys, os


cut = "/usr/bin/cut"
grep = "/usr/bin/grep"
jailpwd=""
callrecord="/var/log/asterisk/cdr-csv/Master.csv"
#outbound VSP name in sip.conf
vsp="pennytel"

#the 9th column represents the number dialed

#command = cut+ " -d \" \" -f 1 " + callrecord + " |" + cut + " -d \",\" -f 3 | " + cut + " -d \\\" -f 2"
#Only obtain the last 100 calls
command = cut+ " -d \",\" -f 3 " +jailpwd+ callrecord + " |" + cut + " -d \\\" -f 2| tail -100"
#print command


#sprint command
fileOpen = os.popen(command,'r')

counter = 0
for x in fileOpen:
	
	#print x
	if (((x[:3]=='003') and (len(x)==12)) or ((x[:1]=='9') and (len(x)==9 ))): #use to compare to 11 to include \n character
		#print x[:len(x)-1] #-1 refers to removing the \n character
		counter+=1



print str(counter)

fileOpen.close()

